package com.jochen.core.world

import com.badlogic.gdx.*
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.utils.*
import com.jochen.core.assets.*
import com.jochen.core.audio.AudioManager
import com.jochen.core.audio.AudioService
import com.jochen.core.screen.*
import com.jochen.core.screen.transitions.DefaultTransition
import com.jochen.core.screen.transitions.FadeTransition
import com.badlogic.gdx.math.MathUtils

class GdxGame: Game(){
    lateinit var screenManager: ScreenManager
    lateinit var assetService: AssetService
    lateinit var audioService: AudioService
    lateinit var audioManager: AudioManager
    lateinit var settingsPre: Preferences
    lateinit var batch: Batch
    lateinit var camera: OrthographicCamera
    lateinit var shapeRenderer: ShapeRenderer
    var glClearColor:Color = Color(
        MathUtils.random(0.7f,1f),
        MathUtils.random(0.7f,1f),
        MathUtils.random(0.7f,1f),1f
    )
    override fun create(){
        settingsPre = Gdx.app.getPreferences(AudioManager.SETTINGS);
        assetService = AssetService(InternalFileHandleResolver());
        audioService = AudioService(this.assetService);
        audioManager = AudioManager(audioService,settingsPre);
        batch = SpriteBatch();
        shapeRenderer = ShapeRenderer();
        camera = OrthographicCamera();
        screenManager = ScreenManager(this).apply{
            addTransitions(FadeTransition(shapeRenderer))
            addScreen(LoadScreen(this@GdxGame,this));
            setScreen(LoadScreen::class)
        }
        setScreen(screenManager)
    }
    
    override fun dispose(){
        settingsPre.flush()
    }
}